package cn.com.orderss.service;

import cn.com.orderss.mapper.OrderMapper;
import cn.com.orderss.entity.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderService {

    @Resource
    private OrderMapper userMapper;

    public void add(Order order) {
        order.setState(0);
        userMapper.insert(order);
    }
    public List<Order> selectAll() {
        return userMapper.selectAll();
    }


    public void update() {
        List<Order> list = userMapper.selectAll();
        Order order = new Order();
        for (int a = 0; a <list.size();a++){
            if (list.get(a).getState() ==0){
                order.setId(list.get(a).getId());
                order.setProjectName(list.get(a).getProjectName());
                order.setAddress(list.get(a).getAddress());
                order.setNotes(list.get(a).getNotes());
                order.setPhone(list.get(a).getPhone());
                order.setState(1);
                userMapper.update(order);
            }else if (list.get(a).getState() ==1){
                order.setId(list.get(a).getId());
                order.setProjectName(list.get(a).getProjectName());
                order.setAddress(list.get(a).getAddress());
                order.setNotes(list.get(a).getNotes());
                order.setPhone(list.get(a).getPhone());
                order.setState(2);
                userMapper.update(order);
            }
        }
    }

    public void upState() {
        List<Order> list = userMapper.selectAll();
        Order order = new Order();
        for (int a = 0; a <list.size();a++){
            if (list.get(a).getState() ==2){
                order.setId(list.get(a).getId());
                order.setProjectName(list.get(a).getProjectName());
                order.setAddress(list.get(a).getAddress());
                order.setNotes(list.get(a).getNotes());
                order.setPhone(list.get(a).getPhone());
                order.setState(3);
                userMapper.update(order);
            }
        }
    }
}
